package com.me.study.beanFactoryPostProcessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * 自定义 BeanFactoryPostProcessor: 可以插手 BeanFactory, 对工厂中的 bean定义 干嘛干嘛
 *
 * @author ME
 * @date   2019/12/22
 */
@Component
public class TestBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) beanFactory.getBeanDefinition("indexDaoImpl1");
        // beanDefinition.getBeanClassName() --> IndexDaoImpl1
		System.out.println("【Spring】 BeanFactoryPostProcessor：把 IndexDaoImpl1 的 Scope 改为原型");
        beanDefinition.setScope(ConfigurableBeanFactory.SCOPE_PROTOTYPE);
    }
}
